package org.gnomus.data;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class assignment extends object {

    public assignment(Entity e) {
        super(e);
        setLab((String) e.getProperty("lab"));
    }

    public assignment(String lab) {
        super("assignment");
        setLab(lab);
    }

    public static List<assignment> fetch(Key gk) {
        List<assignment> ants = new ArrayList<assignment>();
        for (link lnk : link.fetch("group", gk, "assignment", null)) {
            ants.add(new assignment(store.get(lnk.getTargetKey())));
        }
        return ants;
    }

    public void setLab(String lab) {
        put("lab", lab);
    }

    public String getLab() {
        return (String) get("lab");
    }

    public List<member> getMembers() {
        List<member> mbrs = new ArrayList<member>();
        for (access acs : access.fetch(key)) {
            member mbr = acs.getMember();
            mbr.put("access", acs);
            mbrs.add(mbr);
        }
        return mbrs;
    }
}
